import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;

public class Index 
{
	//递归
	static int recursion_reduce(int i)
	{
		if(i == 1)
		{
			return i;
		}
		return recursion_reduce(i-1)+i;
	}
	
	//非递归
	static Integer reduce(int i)
	{
		Stack<Integer> stack = new Stack<>();
		stack.push(i);
		
		Integer result = 0;
		
		while(!stack.empty())
		{
			int current = stack.pop();
			if(current == 1)
			{
				result += current;
			}
			else
			{
				result += current;
				stack.push(current-1);
			}
		}
		
		return result;
	}
	
	public static void main(String[] args) 
	{
		System.out.println(recursion_reduce(4));
		System.out.println(reduce(4));
	}
}